package com.salesmanager.core.business.customer.dao;

import com.salesmanager.core.business.customer.model.CustomerAuths;
import com.salesmanager.core.business.generic.dao.SalesManagerEntityDaoImpl;
import org.springframework.stereotype.Repository;

import javax.persistence.Query;

/**
 * Created by Liutong on 2016/6/18.
 */
@Repository("customerAuthsDao")
public class CustomerAuthsDaoImpl extends SalesManagerEntityDaoImpl<Long, CustomerAuths> implements CustomerAuthsDao {

    @Override
    public CustomerAuths getByCustomerId(Long customerId) {
        StringBuilder hql = new StringBuilder();
        hql.append("select  from CustomerAuths c where 1=1 and c.customer.id = :customerId and c.identityType = 1 ");
        Query query = super.getEntityManager().createQuery(hql.toString());

        query.setParameter("customerId", customerId);

        CustomerAuths customerAuths = (CustomerAuths)query.getSingleResult();
        return customerAuths;
    }
}
